package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description
 * @author: ZXX-挚爱
 * @time: 2023/6/12 10:34
 */

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "C端-购物车接口")
@Slf4j
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

   /** @author ZXX-挚爱
   * @Description 添加购物车
   * @Dete 10:48 2023/6/12
   * @Param [shoppingCartDTO]
   * @return com.sky.result.Result
   **/
    @PostMapping("/add")
    @ApiOperation("购物车添加功能接口")
    public Result shoppingCartAdd(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购物车：{}", shoppingCartDTO);
        shoppingCartService.addShopingCart(shoppingCartDTO);
        return  Result.success();
    }

    /** @author ZXX-挚爱
    * @Description 查看购物车
    * @Dete 14:48 2023/6/12
    * @Param
    * @return com.sky.result.Result<java.util.List<com.sky.dto.ShoppingCartDTO>>
    **/

   @GetMapping("list")
   @ApiOperation("查看购物车功能接口")
   public Result<List<ShoppingCart>> showShoppingCart(){

        List<ShoppingCart> shoppingCartList=shoppingCartService.list();
        return Result.success(shoppingCartList);
   }

   /** @author ZXX-挚爱
   * @Description 清空购物车功能
   * @Dete 15:21 2023/6/12
   * @Param
   * @return com.sky.result.Result<java.lang.String>
   **/

   @DeleteMapping("clean")
   @ApiOperation("清空购物车功能接口")
   public Result<String> cleanShoppingCart(){
       shoppingCartService.clean();
       return Result.success();
   }

   /** @author ZXX-挚爱
   * @Description "删除购物车中的一个商品
   * @Dete 17:12 2023/6/16
   * @Param [shoppingCart]
   * @return com.sky.result.Result
   **/

    @PostMapping("/sub")
    @ApiOperation("删除购物车中的一个商品")
    private Result sub(@RequestBody ShoppingCart shoppingCart){
        shoppingCartService.sub(shoppingCart);
        return Result.success();
    }
}
